
BUILTINS := $(wildcard src/interpreter/builtins/*.js)
CORETMP := build/js/_.js
VERSION := $(shell cat VERSION)

.PHONY: all clean core demo test dist

all: core demo test

clean:
	-rm -rf build/*

core: build/js/ build/js/substandard_lisp.js build/js/biginteger.js

demo: core build/css/ build/js/substandard_terminal.js \
		build/js/jquery-1.5.min.js build/js/jquery.mousewheel.min.js \
		build/js/jquery.terminal-0.3.4.js build/css/jquery.terminal.css \
		build/terminal.htm build/shell.htm

test: core build/css/ build/js/test.js build/js/qunit.js build/test.htm \
		build/css/qunit.css

dist: core demo test
	echo substandard_lisp-$(VERSION) > .fname
	-rm -rf `cat .fname`
	mkdir `cat .fname`
	cp -r Makefile README VERSION build src lib `cat .fname`
	tar -cz --exclude-vcs -f `cat .fname`.tar.gz `cat .fname`
	-rm -rf `cat .fname` .fname

build/js/substandard_lisp.js: $(BUILTINS) src/interpreter/core.js
	cat src/interpreter/core.js > $(CORETMP)
	$(foreach file,$(BUILTINS),cat $(file) | tail -n +18 >> $(CORETMP);)
	cpp -P -C $(CORETMP) >> $@
	-rm -f $(CORETMP)

build/js/test.js: src/test/js/test.js src/test/tests src/test/make_tests.py
	-rm -f $@
	cp src/test/js/test.js $@
	python src/test/make_tests.py src/test/tests >> $@

build/js/%.js: src/*/js/%.js
	cp $< $@

build/js/%.js: lib/%.js
	cp $< $@

build/css/%.css: src/*/css/%.css
	cp $< $@

build/%.htm: src/*/%.htm
	cp $< $@

build/%/:
	mkdir -p $@
